<?php

namespace Modules\Common\General\Notification\SystemError;


use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Modules\Common\Models\SystemError;
use Illuminate\Support\Facades\Mail;

class SystemErrorNofifyQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;
    protected $error;

    public function __construct($errorId)
    {
        $error = SystemError::find($errorId);
        $this->error = $error;
    }

    public function handle()
    {
        foreach (config('app.developer_mails') as $email) {
            $mail = new SystemErrorMail($this->error);
            Mail::to($email)->cc(config('mail.username'))->send($mail);
        }

        // 2：客户端上报
        if ($this->error->type == 2) {
            foreach (config('app.frontend_mails') as $email) {
                $mail = new SystemErrorMail($this->error);
                Mail::to($email)->cc(config('mail.username'))->send($mail);
            }
        }


        $this->error->status = 2; //2：已通知
        $this->error->save();
    }

}